// 微信分享默认调用接口
var qsd=querystring.parse();
var $appid,$timestamp,$noncestr,$signature,$parentid;
//获取当前页面的url
var linkUrl = window.location.href;
var url=linkUrl.split('?')[0];
var orderNo=(qsd.orderNo&&qsd.orderNo>0)?qsd.orderNo:'';
var odertype=(qsd.odertype&&qsd.odertype>0)?qsd.odertype:'';
//encodeURIComponent(),请求后台接口需要用encodeURIComponent()
var encodeUrl = encodeURIComponent(linkUrl); 
$.ajax({
    type : "GET",
    url : "/api/share/wxShare"+"?url=" + 'linkUrl',
    cache : false,
    async : false,
    success : function(res) {
        var data = res.data;
        console.log(data);
        if(res.code == 0){
            $appid = res.data.appid;  // appid
            $timestamp = res.data.timestamp;   // timestamp
            $noncestr = res.data.noncestr; // noncestr
            $signature = res.data.signature;  // signature
			$parentid =res.data.user_id
            //**配置微信信息**
            wx.config ({
                debug : true,
                appId : $appid,
                timestamp : $timestamp,
                nonceStr : $noncestr,
                signature : $signature,
                jsApiList : [
                    // 所有要调用的 API 都要加到这个列表中
                    'onMenuShareTimeline',
                    'onMenuShareAppMessage',
                    'onMenuShareQQ',
                    'onMenuShareWeibo',
                    'onMenuShareQZone'
                ]
            });
            wx.ready (function () {
                // 微信分享的数据
                var shareData = {
                    "imgUrl" : "",
                    "link" : "http://test.newzqxq.com/yichengyihe/html/index.html?orderNo="+orderNo+"&parentid="+$parentid+'odertype='+odertype,
                    "desc" : "一城一盒",
                    "title" :"一城一盒",
                    success : function (res) {
                        // 分享成功可以做相应的数据处理
						console.log(res)
                    }
                };
                //分享微信朋友圈
                wx.onMenuShareTimeline (shareData);
                //分享给朋友
				wx.onMenuShareAppMessage(shareData)
                //分享到qq
                wx.onMenuShareQQ (shareData);
                //分享到微博
                wx.onMenuShareWeibo (shareData);
                //分享到qq空间
                wx.onMenuShareQZone(shareData);
            });
        }
    },
    error : function(msg){
		console.log(msg)
    }
});
